// ==UserScript==
// @name         电商课双平台监控
// @namespace    https://gitee.com/vbox007/Tampermonkey/raw/master/
// @version      2.0.2.12
// @description  我也不想回答那些奇怪的问题，所以别问我怎么做到的
// @author       vbox007
// @icon         
// @match        https://zt.hiboos.com/monitor
// @connect      hiboos.com
// @connect      dmall.com
// @connect      jddj.com
// @connect      meituan.com
// @connect      ele.me
// @run-at       document-start
// @grant        GM_xmlhttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @require      https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.js
// ==/UserScript==

(function () {
    'use strict';
    var $ = function (x) {
        return document.getElementById(x);
    };//ID定位
    var myec = 0;//错误码
    var dmsid = 0;//多点中的店号
    var oldlist = '';
    var sforderids = '';
    var dplatform = ['', '京东', '美团', '饿了么'];
    var pplatform = [
        '',
        '',
        '',
        ''
    ];//海博三平台的图片
    var loadnum = [0, 1];
    var dmallphone = {};
    (function () {
        document.head.innerHTML = '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />'
            + '<link rel="shortcut icon" type="image/ico" href="">'
            + '<title>vbox007\'s E-commerce monitor</title>'
            + '<style id="test">\n'
            + 'table,table tr th, table tr td {border:1px solid #002244;font-size:12px;}\n'
            + 'table {min-height:25px;line-height:16px;text-align:center;border-collapse:collapse;margin-bottom:0;}\n'
            + '.f-center {width:100%;overflow:auto;margin: 0 auto;text-align:center;}\n'
            + '.dd-center {float:left;text-align:center;background:#f9cc9d;}\n'
            + '.hb-center {float:left;text-align:center;background:#8bb5c0;}\n'
            + '</style>';
    })();//修改页面head
    window.onresize = (function () {
        if (window.innerWidth > window.innerHeight) {
            $('ddxt').style = 'width:50%;height:auto;min-height:100%;';
            $('hbxt').style = 'width:50%;height:auto;min-height:100%;';
        } else {
            $('ddxt').style = 'width:100%;height:50%;overflow:auto;';
            $('hbxt').style = 'width:100%;height:50%;overflow:auto;';
        }
    });//页面尺寸被改变时修改div的大小
    (function () {
        var gm_autopack = GM_getValue('autopack', 0);
        var gm_autoretpl = GM_getValue('autoretpl', 0);
        var tinnh = function (t_ch) {
            var rttb = '<table border="1" align="center" class="cabinTable table table-striped table-hover"><thead bgcolor="';//return tag table
            if (t_ch & 1) {
                t_ch >>= 1;
                rttb += '#99dda0"><tr><th>订单小号</th>';
                if (t_ch & 1) {
                    t_ch >>= 1;
                    rttb += '<th>平台单号</th><th>订单尺寸</th><th>拣货截止时间</th><th>完成支付时间</th><th>收货人</th><th>收货号码</th><th>地址</th></tr></thead><tbody id="';
                    switch (t_ch) {
                        case 0:
                            rttb += 'jddftb';
                            break;
                        case 1:
                            rttb += 'mtdftb';
                            break;
                        case 2:
                            rttb += 'eldftb';
                            break;
                    }
                    rttb += '"/></table>';
                    return rttb;
                } else {
                    rttb += (t_ch == 0 ? '<th>拣货中</th>' : '') + '<th>订单尺寸</th><th>' + (t_ch == 0 ? '拣货' : '配送') + '剩余时长</th><th>' + (t_ch == 0 ? '拣货' : '送达')
                        + '截止时间</th><th>收货号码</th><th>地址</th></tr></thead><tbody id="hbxt' + (t_ch == 0 ? '' : 'p') + 'tb"/></table>';
                }
                return rttb;
            } else {
                t_ch >>= 1;
                rttb += '#FFFAC7"><tr><th>订单号</th><th>结算类型</th><th>订单状态</th><th>拣货员</th><th>配送员</th><th>合流码</th><th>配送方式</th>'
                    + (t_ch == 0 ? '<th>拣货剩余</th>' : '')
                    + (t_ch == 1 ? '<th>配送剩余</th>' : '')
                    + '<th>期望送达时间</th><th>收货号码</th><th>收货人</th><th>地址</th></tr></thead><tbody id="';
                switch (t_ch) {
                    case 0:
                        rttb += 'ddxttb';
                        break;
                    case 1:
                        rttb += 'ddxtptb';
                        break;
                    case 2:
                        rttb += 'ddxtdonetb';
                        break;
                }
                rttb += '"/></table>';
                return rttb;
            }
            return 'error';
        };
        document.body.innerHTML = '<div class="f-center">'
            + '<div id="ddxt" class="dd-center"><div id="ddxtnli" style="display:none;"><p><a href="https://partner.dmall.com/" target="_blank" title="点击进入登陆页">多点来客系统尚未登陆，请确认登陆状态。<br/><span id="dmecd"/></a></p></div>'
            + '<div id="ddxtdp" style="display:none;">'
            + '<select id="storeid" style="display:none;"></select>'
            + '<p>未完成拣货订单(<span id="dmwpack">0</span>单)</p>'
            + '<select id="autopack">'
            + '<option value="0">关闭自动打包</option>'
            + '<option value="1"' + (gm_autopack == 1 ? ' selected' : '') + '>拣货完成后70秒左右自动打包</option>'
            + '<option value="2"' + (gm_autopack == 2 ? ' selected' : '') + '>拣货剩余120秒以下时自动打包</option>'
            + '<option value="3"' + (gm_autopack == 3 ? ' selected' : '') + '>拣货完成70秒或剩余时间低于120时自动打包</option>'
            + '</select>' + tinnh(0)
            + '<p>未配送完成订单(<span id="dmwdone">0</span>单)</p>'
            + '<a id="sfall" href title="点击签收全部自提订单">一键签收全部自提订单</a><br/>'
            + '<select id="autoretplck"><option value="0">关闭重发配送</option><option value="1"' + (gm_autoretpl == 1 ? ' selected' : '') + '>配送剩余45分钟以下时撤回达达配送转发蜂鸟</option></select>' + tinnh(2)
            + '<p>完结订单(<span id="dmdone">0</span>单)</p>' + tinnh(4)
            + '</div>'
            + '</div>'
            + '<div id="hbxt" class="hb-center"><div id="hbxtnli" style="display:none;"><p><a href="https://zt.hiboos.com/" target="_blank" title="点击进入登陆页">海博系统尚未登陆，请确认登陆状态。<br/><span id="hbecd"/></a></p></div>'
            + '<div id="jddf" style="display:none;">'
            + '<p>京东未同步入海博的订单(<span id="jdamount">0</span>单)</p>' + tinnh(3)
            + '</div>'
            + '<div id="mtdf" style="display:none;">'
            + '<p>美团未同步入海博的订单(<span id="mtamount">0</span>单)</p>' + tinnh(7)
            + '</div>'
            + '<div id="eldf" style="display:none;">'
            + '<p>饿了么未同步入海博的订单(<span id="elamount">0</span>单)</p>' + tinnh(11)
            + '</div>'
            + '<div id="hbxtdp" style="display:none;">'
            + '<p>海博未完成拣货订单(<span id="hbwpack">0</span>单)</p>' + tinnh(1)
            + '<p>海博待配送订单(<span id="hbwdone">0</span>单)</p>' + tinnh(5)
            + '</div>'
            + '</div>'
            + '</div>'
            + '<div id="p_qrcode" style="position:absolute;display:none;" onclick="this.style.display=\'none\';"/>';
        window.onresize();
        $('autopack').onchange = (function (ev) {
            GM_setValue('autopack', parseInt(ev.target.value));
        });
        $('autoretplck').onchange = (function (ev) {
            GM_setValue('autoretpl', parseInt(ev.target.value));
        });
        $('storeid').onchange = (function (ev) {
            dmsid = parseInt(ev.target.value);
            console.log(dmsid);
        });
    })();//修改页面body
    var get_dmall_id = function () {
        loadnum[0] = 2;
        GM_xmlhttpRequest({
            method: "post",
            url: "https://waybillsmartallot-partner.dmall.com/api/getStoreList",
            data: null,
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                try {
                    var pobj = JSON.parse(res.responseText);
                    for (var i = 0; i < pobj.data.length; i++) {
                        $('storeid').options[i] = new Option(pobj.data[i].storeName);
                        $('storeid').options[i].value = pobj.data[i].storeId;
                    }
                    dmsid = $('storeid').options[0].value;
                    $('storeid').options[0].selected = true;
                    $('storeid').style.display = 'block';
                    myec &= ~3;
                    loadnum[0] = 3;
                } catch (error) {
                    myec |= 1;
                    loadnum[0] = 3;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                myec |= 2;
                loadnum[0] = 3;
                console.log('*');
                console.log(err);
                console.log('*');
            }
        });
    };//取多点来客系统中的门店编号
    get_dmall_id();
    var changerow = function (tbid, crows) {
        var tbev = $(tbid);
        var tcells;
        tcells = tbev.parentNode.rows[0].cells.length;
        var tadre = tbev.rows.length - crows;
        var i = 0;
        for (i = 0; i < tadre; i++) {
            tbev.lastChild.remove();
        }
        tadre = -tadre;
        for (i = 0; i < tadre; i++) {
            var ntr = document.createElement("tr");
            ntr.innerHTML = new Array(tcells + 1).join('<td></td>');
            tbev.appendChild(ntr);
        }
    };//修改表格tbody的行数
    var getstrtime = function (difft) {
        var nowdate = new Date();
        if (difft) {
            nowdate.setTime(nowdate.getTime() + difft);
        }
        var nowmon = nowdate.getMonth() + 1;
        var strDate = nowdate.getDate();
        if (nowmon >= 1 && nowmon <= 9) {
            nowmon = "0" + nowmon;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var cdate = nowdate.getFullYear() + '-' + nowmon + '-' + strDate;
        return cdate;
    };//获取今天的日期文本
    var js_packput = function (orderid, reltime) {
        if (orderid) {
            GM_xmlhttpRequest({
                method: "GET",
                url: "https://fulproduce-partner.dmall.com/pack/pack?erpStoreId=" + dmsid + "&optType=1&orderIds%5B%5D=" + orderid + "&boxType=&boxTypeName=&_=",
                headers: {
                    "accept": "application/json, text/javascript, */*; q=0.01",
                    "accept-language": "zh-CN,zh;q=0.9",
                    "sec-fetch-dest": "empty",
                    "sec-fetch-mode": "cors",
                    "sec-fetch-site": "same-site"
                },
                onload: function (res) {
                    var pobj = JSON.parse(res.responseText);
                    console.log(pobj);
                    if (pobj.code == "success") {
                        GM_setValue('o' + orderid, 'packed');
                    };
                    if (reltime) {
                        setTimeout(function () { location.reload() }, reltime);
                    }
                }
            });
        }
    };//打包上架
    var tpl_resend = function (orderId) {
        GM_xmlhttpRequest({
            method: "post",
            url: 'https://waybill-partner.dmall.com/tpl/cancel/cancel',
            data: 'carrierId=38&orderIds=' + orderId + '&erpStoreId=' + dmsid,
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                var pobj = JSON.parse(res.responseText);
                if (pobj.code == '0000') {
                    var sendto130 = GM_xmlhttpRequest({
                        method: "post",
                        url: 'https://waybill-partner.dmall.com/tpl/task/distribution',
                        data: 'carrierId=130&carrierName=%E8%9C%82%E9%B8%9F%E9%85%8D%E9%80%81&orderIds=' + orderId + '&erpStoreId=' + dmsid,
                        headers: {
                            "accept": "application/json, text/javascript, */*; q=0.01",
                            "accept-language": "zh-CN,zh;q=0.9",
                            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                            "sec-fetch-dest": "empty",
                            "sec-fetch-mode": "cors",
                            "sec-fetch-site": "same-site"
                        },
                        onload: function (res) {
                            var pobj = JSON.parse(res.responseText);
                            console.log(pobj);
                        }
                    });
                    setTimeout(sendto130, 2048);
                } else {
                    console.log(pobj);
                }
            }
        });
    };//撤回达达转发蜂鸟
    var reovertime = function (overtime, diffmin) {
        var d1 = new Date();//获取到当前的时间
        var d1Ms = d1.getTime();
        var differMs = overtime - d1Ms - (diffmin ? 60000 : 0);//相差的毫秒数
        var isTO = differMs < 0;
        differMs = isTO ? -differMs : differMs;
        var minutes = parseInt(differMs / (60000));//分钟
        var seconds = parseInt((differMs % (60000)) / 1000);//秒
        //当前分秒为个位数字时，对其进行的处理
        seconds = seconds < 10 ? "0" + seconds : seconds;
        return (isTO ? '<span style="color: #ffffff;background: #000000;font-weight: bold;">超时</span>' + minutes : minutes) + "分" + seconds + "秒";
    };//时间计算，主要是剩余时间
    var bind_qrcode = function (a_tag, c_sys, c_add, c_name, c_phone) {
        a_tag.onclick = (function (ev) {
            var js_ev = ev.target.parentNode.parentNode.children;
            if (typeof c_name == "number") {
                c_name = js_ev[c_name].innerText;
            }
            var qrstr, e, scrollX, scrollY, x, y;
            if (c_sys == '多点') {
                var orderId = js_ev[0].innerText;
                if (dmallphone[orderId] == undefined) {
                    GM_xmlhttpRequest({
                        method: "GET",
                        url: "https://fulproduce-partner.dmall.com/produceOrderDetail/bindAXB?aNumber=13000000000&orderId=" + orderId + "&phoneType=1",
                        "headers": {
                            "accept": "application/json, text/javascript, */*; q=0.01",
                            "accept-language": "zh-CN,zh;q=0.9",
                            "sec-ch-ua": "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\"",
                            "sec-ch-ua-mobile": "?0",
                            "sec-fetch-dest": "empty",
                            "sec-fetch-mode": "cors",
                            "sec-fetch-site": "same-site",
                            "referrer": "https://partner.dmall.com/",
                            "referrerPolicy": "strict-origin-when-cross-origin",
                            "mode": "cors",
                            "credentials": "include"
                        },
                        onload: function (res) {
                            try {
                                var pobj = (JSON.parse(res.responseText));
                                dmallphone[orderId] = pobj.data.bNumber;
                                js_ev[c_phone].lastChild.innerText = dmallphone[orderId];
                                qrstr = 'BEGIN:VCARD\r\nFN:' + c_sys + '_' + js_ev[c_add].innerText + '_' + c_name + '\r\nTEL;CELL,VOICE:' + js_ev[c_phone].innerText + '\r\nEND:VCARD';
                                qrm.makeCode(qrstr);
                                e = event || window.event;
                                scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
                                scrollY = document.documentElement.scrollTop || document.body.scrollTop;
                                x = e.pageX || e.clientX + scrollX;
                                y = e.pageY || e.clientY + scrollY;
                                $('p_qrcode').style.left = x + 10 + "px";
                                $('p_qrcode').style.top = y + 10 + "px";
                                $('p_qrcode').style.display = 'block';
                            } catch (error) {
                                console.log('*');
                                console.log(error.message);
                                console.log('*');
                            }
                        },
                        onerror: function (err) {
                            console.log(err);
                        }
                    });
                } else {
                    try {
                        qrstr = 'BEGIN:VCARD\r\nFN:' + c_sys + '_' + js_ev[c_add].innerText + '_' + c_name + '\r\nTEL;CELL,VOICE:' + js_ev[c_phone].innerText + '\r\nEND:VCARD';
                        qrm.makeCode(qrstr);
                        e = event || window.event;
                        scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
                        scrollY = document.documentElement.scrollTop || document.body.scrollTop;
                        x = e.pageX || e.clientX + scrollX;
                        y = e.pageY || e.clientY + scrollY;
                        $('p_qrcode').style.left = x + 10 + "px";
                        $('p_qrcode').style.top = y + 10 + "px";
                        $('p_qrcode').style.display = 'block';
                    } catch (error) {
                        console.log('*');
                        console.log(error.message);
                        console.log('*');
                    }
                }
            } else {
                try {
                    qrstr = 'BEGIN:VCARD\r\nFN:' + c_sys + '_' + js_ev[c_add].innerText + '_' + c_name + '\r\nTEL;CELL,VOICE:' + js_ev[c_phone].innerText + '\r\nEND:VCARD';
                    qrm.makeCode(qrstr);
                    e = event || window.event;
                    scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
                    scrollY = document.documentElement.scrollTop || document.body.scrollTop;
                    x = e.pageX || e.clientX + scrollX;
                    y = e.pageY || e.clientY + scrollY;
                    $('p_qrcode').style.left = x + 10 + "px";
                    $('p_qrcode').style.top = y + 10 + "px";
                    $('p_qrcode').style.display = 'block';
                } catch (error) {
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            }
            return false;
        });
    };//绑定创建二维码事件
    var bind_packput = function (a_tag) {
        a_tag.onclick = (function (ev) {
            js_packput(ev.target.parentNode.parentNode.children[0].innerText, 4096);
            return false;
        });
    };//绑定点击打包事件
    var re_time_line = function (linerow, line_time) {
        if (line_time > 3600000) {
            linerow.style.background = "linear-gradient(to right, #00c000 100%,#ffff00 0%)";
        } else if (line_time > 1800000) {
            linerow.style.background = "linear-gradient(to right, #00c000 " + (line_time - 1800000) / 18000 + "%,#ffff00 0%)";
        } else if (line_time > 0) {
            linerow.style.background = "linear-gradient(to right, #ffff00 " + line_time / 18000 + "%,#ff0000 0%)";
        } else {
            linerow.style.background = "#ff0000";
        }
    };
    var redm_wait_pack = function () {
        var gm_autopack = GM_getValue('autopack', 0);
        for (var i = 0; i < $('ddxttb').rows.length; i++) {
            var d2 = $('ddxttb').rows[i].cells[8].innerText.split(' ');
            var tdd = d2[1].split('-');
            var d2Ms = new Date(d2[0] + ' ' + tdd[0]).getTime();
            tdd[0] = new Date(d2[0] + ' ' + tdd[0]).getTime();
            tdd[1] = new Date(d2[0] + ' ' + tdd[1]).getTime();
            if (tdd[1] - tdd[0] > 4500000) {
                d2Ms = (tdd[1] - tdd[0]) * 0.4 + d2Ms;
            }
            var ordid = $('ddxttb').rows[i].cells[0].innerText;
            var jnow = new Date();
            var nowdd = new Date();//获取到当前的时间
            var nowMsdd = nowdd.getTime();
            var linegdd = d2Ms - nowMsdd;//相差的毫秒数
            if (gm_autopack & 1 && $('ddxttb').rows[i].cells[2].innerText == "商家已结算" && (jnow - parseInt($('ddxttb').rows[i].cells[5].lastChild.innerText) > 72188) && GM_getValue('o' + ordid, 'nopack') != 'packed') {
                js_packput(ordid);
            }
            if (gm_autopack & 2 && linegdd < 120000 && GM_getValue('o' + ordid, 'nopack') != 'packed') {
                js_packput(ordid);
            }
            $('ddxttb').rows[i].cells[7].innerHTML = reovertime(d2Ms, true);
            re_time_line($('ddxttb').rows[i], linegdd);
        }
    };//刷新多点拣货剩余时长
    var get_dmall_wait_pack = function () {
        loadnum[0] = 4;
        GM_xmlhttpRequest({
            method: "post",
            url: 'https://fulproduce-partner.dmall.com/produceOrderList/list',
            data: 'storeIds=' + dmsid + '&shipmentBeginTime=' + getstrtime() + '+00%3A00%3A00&shipmentEndTime=' + getstrtime(86400000) + '+23%3A59%3A59&orderStatus=4%2C8%2C9%2C10%2C11%2C12%2C13%2C15&pageSize=512&pageNo=1',
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                try {
                    var pobj = JSON.parse(res.responseText);//解析json
                    var amount = (pobj.data.result ? pobj.data.result.length : 0);//待拣货订单总数
                    $('dmwpack').innerText = amount;//显示订单数量
                    if (amount) {
                        pobj.data.result.sort(function (a, b) {
                            return (a.produce_order__order_id - b.produce_order__order_id);
                        });//先按单号排序
                        pobj.data.result.sort(function (a, b) {
                            if (a.shipmentTimeDesc < b.shipmentTimeDesc) {
                                return -1;
                            }
                            if (a.shipmentTimeDesc > b.shipmentTimeDesc) {
                                return 1;
                            }
                            return 0;
                        });//再按时间排序
                    }
                    var pdr = new Array(amount);
                    for (var i = 0; i < amount; i++) {
                        pdr[i] = new Array(12);
                    }
                    changerow('ddxttb', amount);
                    for (i = 0; i < amount; i++) {
                        $('ddxttb').rows[i].cells[0].innerHTML = '<a href="https://partner.dmall.com/#index/produceCenter/detail:orderId=' + pobj.data.result[i].produce_order__order_id + '" target="_blank" title="点击进入订单详情">' + pobj.data.result[i].produce_order__order_id;
                        $('ddxttb').rows[i].cells[1].innerHTML = pobj.data.result[i].tradeTypeDesc;
                        if (pobj.data.result[i].orderStatusDesc == "商家已结算") {
                            $('ddxttb').rows[i].cells[2].innerHTML = '<a href title="点击进行打包">商家已结算</a>';
                            bind_packput($('ddxttb').rows[i].cells[2].lastChild, 4096);
                        } else {
                            $('ddxttb').rows[i].cells[2].innerHTML = '<a href="https://fulproduce-partner.dmall.com/produceOrderDetail/detail?orderId=' + pobj.data.result[i].produce_order__order_id + '&orderOrigin=" target="_blank" title="点击进入条码打印页">' + pobj.data.result[i].orderStatusDesc + '</a>';
                        }
                        $('ddxttb').rows[i].cells[3].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__picker_name;
                        $('ddxttb').rows[i].cells[4].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__delivery_name + '(' + pobj.data.result[i].produceProcessVo.produce_process__delivery_tel + ')';
                        if (pobj.data.result[i].produce_order__confluence_code != undefined) {
                            $('ddxttb').rows[i].cells[5].innerHTML = pobj.data.result[i].produce_order__confluence_code + '<span hidden>' + pobj.data.result[i].produceProcessVo.produce_process__end_time + '</span>';
                        } else {
                            $('ddxttb').rows[i].cells[5].innerHTML = ''
                        }
                        $('ddxttb').rows[i].cells[6].innerHTML = pobj.data.result[i].shipmentTypeDesc;
                        $('ddxttb').rows[i].cells[8].innerHTML = pobj.data.result[i].shipmentTimeDesc;
                        $('ddxttb').rows[i].cells[9].innerHTML = '<a href title="显示二维码">' + pobj.data.result[i].produce_order__consignee_phone + '</a>';
                        $('ddxttb').rows[i].cells[10].innerHTML = pobj.data.result[i].produce_order__consignee_name;
                        if (pobj.data.result[i].shipmentTypeDesc == '自提') {
                            $('ddxttb').rows[i].cells[11].innerHTML = '自提';
                        } else {
                            $('ddxttb').rows[i].cells[11].innerHTML = pobj.data.result[i].produce_order__consignee_address.replace('湖北省 武汉市 ', '').replace('湖北省武汉市', '');
                        }
                        bind_qrcode($('ddxttb').rows[i].cells[9].lastChild, '多点', 11, 10, 9);

                    }
                    redm_wait_pack();
                    $('ddxtdp').style.display = '';//取消div的隐藏
                    myec &= ~12;
                    loadnum[0] = 5;
                } catch (error) {
                    myec |= 4;
                    loadnum[0] = 5;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                myec |= 8;
                console.log(err);
                loadnum[0] = 5;
            }
        });
    };//取多点未拣货订单
    var redm_wait_done = function () {
        for (var i = 0; i < $('ddxtptb').rows.length; i++) {
            if ($('ddxtptb').rows[i].cells[6].innerText == '自提') {
                $('ddxtptb').rows[i].style.background = '';
            } else {
                var d1 = new Date();//获取到当前的时间
                var d1Ms = d1.getTime();
                var d2 = $('ddxtptb').rows[i].cells[8].innerHTML.split(' ');
                d2[1] = d2[1].split('-')[1];
                d2 = new Date(d2[0] + ' ' + d2[1]);
                var d2Ms = d2.getTime();
                d1Ms = d2Ms - d1Ms;
                if (d1Ms < 2670000 && d1Ms > 2668000 && GM_getValue('autoretpl', 0) == 1 && ('待分配配送员，配送分配，再投入站'.indexOf($('ddxtptb').rows[i].cells[2].innerText) != -1)) {
                    tpl_resend($('ddxtptb').rows[i].cells[0].innerText);
                }
                $('ddxtptb').rows[i].cells[7].innerHTML = reovertime(d2Ms);
                var nowddp = new Date();//获取到当前的时间
                var nowMsddp = nowddp.getTime();
                var linegddp = d2Ms - nowMsddp;//相差的毫秒数
                re_time_line($('ddxtptb').rows[i], linegddp);
            }
        }
    };//更新多点配送剩余时长
    var js_signfor = function (confluence_code, orderid, consignee_name, consignee_phone, selfCode, reltime) {
        var cfmsg = '请核对好客户手机号、收货人与订单号'
            + '\n合流码:' + confluence_code
            + '\n订单号:' + orderid
            + '\n收货人:' + consignee_name
            + '\n手机号:' + consignee_phone
            + '\n自提码:' + selfCode;
        if (confluence_code == 'sfall') {
            selfCode = (orderid.length + 1) / 13 >>> 0;
            if (selfCode == 0) {
                alert('当前没有待自提订单！');
                return;
            }
            cfmsg = '您确定要签收所有的自提订单么？'
                + '\n点击确定后总共会有' + selfCode + '单被签收！';
        };
        if (confirm(cfmsg)) {
            GM_xmlhttpRequest({
                method: "post",
                url: 'https://waybill-partner.dmall.com/selfConfirm/save',
                data: 'orderIds=' + orderid,
                headers: {
                    "accept": "application/json, text/javascript, */*; q=0.01",
                    "accept-language": "zh-CN,zh;q=0.9",
                    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                    "sec-fetch-dest": "empty",
                    "sec-fetch-mode": "cors",
                    "sec-fetch-site": "same-site"
                },
                onload: function (res) {
                    console.log(res.responseText);
                    if (reltime) {
                        setTimeout(function () { location.reload() }, reltime);
                    }
                }
            });
        } else {
            console.log('no' + orderid);
        }
    };//自提签收
    (function () {
        $('sfall').onclick = (function (ev) {
            js_signfor('sfall', sforderids);
            return false;
        });
    })();//绑定一键签收事件
    var bind_signfor = function (a_tag) {
        a_tag.onclick = (function (ev) {
            var js_ev = ev.target.parentNode.parentNode.children;
            js_signfor(js_ev[5].innerText, js_ev[0].innerText, js_ev[10].innerText, js_ev[9].innerText, js_ev[11].innerText, 4096);
            return false;
        });
    };//绑定点击签收事件
    var get_dmall_wait_done = function () {
        loadnum[0] = 6;
        GM_xmlhttpRequest({
            method: "post",
            url: 'https://fulproduce-partner.dmall.com/produceOrderList/list',
            data: 'storeIds=' + dmsid + '&orderStatus=16%2C17%2C18%2C32%2C33%2C36%2C37&pageSize=512&pageNo=1',
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                try {
                    var pobj = JSON.parse(res.responseText);//解析json
                    var amount = (pobj.data.result ? pobj.data.result.length : 0);//待完成订单总数
                    $('dmwdone').innerText = amount;//显示订单数量
                    if (amount) {
                        pobj.data.result.sort(function (a, b) {
                            return (a.produce_order__order_id - b.produce_order__order_id);
                        });//先按单号排序
                        pobj.data.result.sort(function (a, b) {
                            if (a.shipmentTimeDesc < b.shipmentTimeDesc) {
                                return -1;
                            }
                            if (a.shipmentTimeDesc > b.shipmentTimeDesc) {
                                return 1;
                            }
                            return 0;
                        });//再按时间排序
                    }
                    var pdr = new Array(amount);
                    for (var i = 0; i < amount; i++) {
                        pdr[i] = new Array(12);
                    }
                    changerow('ddxtptb', amount);
                    sforderids = ''
                    for (i = 0; i < amount; i++) {
                        if (GM_getValue('o' + pobj.data.result[i].produce_order__order_id, 'nopack') == 'packed') {
                            GM_deleteValue('o' + pobj.data.result[i].produce_order__order_id);
                        }
                        $('ddxtptb').rows[i].cells[0].innerHTML = '<a href="https://partner.dmall.com/#index/produceCenter/detail:orderId=' + pobj.data.result[i].produce_order__order_id + '" target="_blank" title="点击进入订单详情">' + pobj.data.result[i].produce_order__order_id;
                        $('ddxtptb').rows[i].cells[1].innerHTML = pobj.data.result[i].tradeTypeDesc;
                        $('ddxtptb').rows[i].cells[2].innerHTML = pobj.data.result[i].orderStatusDesc;
                        $('ddxtptb').rows[i].cells[3].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__picker_name;
                        $('ddxtptb').rows[i].cells[4].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__delivery_name + '(' + pobj.data.result[i].produceProcessVo.produce_process__delivery_tel + ')';
                        if (pobj.data.result[i].produce_order__confluence_code != undefined) {
                            $('ddxtptb').rows[i].cells[5].innerHTML = pobj.data.result[i].produce_order__confluence_code + '<span hidden>' + pobj.data.result[i].produceProcessVo.produce_process__end_time + '</span>';
                        } else {
                            $('ddxtptb').rows[i].cells[5].innerHTML = '';
                        }
                        $('ddxtptb').rows[i].cells[6].innerHTML = pobj.data.result[i].shipmentTypeDesc;
                        if (pobj.data.result[i].shipmentTypeDesc == '自提') {
                            $('ddxtptb').rows[i].cells[7].innerHTML = '<a href class="asignfor" title="点击签收">点击签收</a>';
                            sforderids += $('ddxtptb').rows[i].cells[0].innerText + ','
                        }
                        $('ddxtptb').rows[i].cells[8].innerHTML = pobj.data.result[i].shipmentTimeDesc;
                        $('ddxtptb').rows[i].cells[9].innerHTML = '<a href title="显示二维码">' + pobj.data.result[i].produce_order__consignee_phone + '</a>';
                        $('ddxtptb').rows[i].cells[10].innerHTML = pobj.data.result[i].produce_order__consignee_name;
                        if (pobj.data.result[i].shipmentTypeDesc == '自提') {
                            var selfCode = pobj.data.result[i].produce_order__extend_fields;
                            try {
                            selfCode = selfCode.split('selfCode": "')[1];
                            selfCode = selfCode.split('"')[0];
                            $('ddxtptb').rows[i].cells[11].innerHTML = '自提码:' + selfCode;
                            } catch(error) {
                                console.log(error.message);
                                $('ddxtptb').rows[i].cells[11].innerHTML = '自提不打码';
                        };
                            bind_signfor($('ddxtptb').rows[i].cells[7].lastChild);
                        } else {
                            $('ddxtptb').rows[i].cells[11].innerHTML = pobj.data.result[i].produce_order__consignee_address.replace('湖北省 武汉市 ', '').replace('湖北省武汉市', '');
                        }
                        bind_qrcode($('ddxtptb').rows[i].cells[9].lastChild, '多点', 11, 10, 9);
                    }
                    sforderids = sforderids.substring(0, sforderids.length - 1)
                    redm_wait_done();
                    $('ddxtdp').style.display = '';//取消div的隐藏
                    myec &= ~48;
                    loadnum[0] = 7;
                } catch (error) {
                    myec |= 16;
                    loadnum[0] = 7;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                myec |= 32;
                console.log(err);
                loadnum[0] = 7;
            }
        });
    };//取多点未完成订单
    var get_dmall_done = function () {
        loadnum[0] = 8;
        GM_xmlhttpRequest({
            method: "post",
            url: 'https://fulproduce-partner.dmall.com/produceOrderList/list',
            data: 'storeIds=' + dmsid + '&shipmentBeginTime=' + getstrtime() + '+00%3A00%3A00&shipmentEndTime=' + getstrtime(86400000) + '+23%3A59%3A59&orderStatus=64%2C65%2C128%2C133%2C135&pageSize=512&pageNo=1',
            headers: {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site"
            },
            onload: function (res) {
                try {
                    var pobj = JSON.parse(res.responseText);//解析json
                    var amount = (pobj.data.result ? pobj.data.result.length : 0);//待完成订单总数
                    $('dmdone').innerText = amount;//显示订单数量
                    if (amount) {
                        pobj.data.result.sort(function (a, b) {
                            return (a.produce_order__order_id - b.produce_order__order_id);
                        });//先按单号排序
                        pobj.data.result.sort(function (a, b) {
                            if (a.shipmentTimeDesc < b.shipmentTimeDesc) {
                                return -1;
                            }
                            if (a.shipmentTimeDesc > b.shipmentTimeDesc) {
                                return 1;
                            }
                            return 0;
                        });//再按时间排序
                    }
                    var pdr = new Array(amount);
                    for (var i = 0; i < amount; i++) {
                        pdr[i] = new Array(11);
                    }
                    changerow('ddxtdonetb', amount);
                    for (i = 0; i < amount; i++) {
                        if (GM_getValue('o' + pobj.data.result[i].produce_order__order_id, 'nopack') == 'packed') {
                            GM_deleteValue('o' + pobj.data.result[i].produce_order__order_id);
                        }
                        $('ddxtdonetb').rows[i].cells[0].innerHTML = '<a href="https://partner.dmall.com/#index/produceCenter/detail:orderId=' + pobj.data.result[i].produce_order__order_id + '" target="_blank" title="点击进入订单详情">' + pobj.data.result[i].produce_order__order_id;
                        $('ddxtdonetb').rows[i].cells[1].innerHTML = pobj.data.result[i].tradeTypeDesc;
                        $('ddxtdonetb').rows[i].cells[2].innerHTML = pobj.data.result[i].orderStatusDesc;
                        $('ddxtdonetb').rows[i].cells[3].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__picker_name;
                        $('ddxtdonetb').rows[i].cells[4].innerHTML = pobj.data.result[i].produceProcessVo.produce_process__delivery_name + '(' + pobj.data.result[i].produceProcessVo.produce_process__delivery_tel + ')';
                        if (pobj.data.result[i].produce_order__confluence_code != undefined) {
                            $('ddxtdonetb').rows[i].cells[5].innerHTML = pobj.data.result[i].produce_order__confluence_code + '<span hidden>' + pobj.data.result[i].produceProcessVo.produce_process__end_time + '</span>';
                        } else {
                            $('ddxtdonetb').rows[i].cells[5].innerHTML = ''
                        }
                        $('ddxtdonetb').rows[i].cells[6].innerHTML = pobj.data.result[i].shipmentTypeDesc;
                        $('ddxtdonetb').rows[i].cells[7].innerHTML = pobj.data.result[i].shipmentTimeDesc;
                        $('ddxtdonetb').rows[i].cells[8].innerHTML = '<a href title="显示二维码">' + pobj.data.result[i].produce_order__consignee_phone + '</a>';
                        $('ddxtdonetb').rows[i].cells[9].innerHTML = pobj.data.result[i].produce_order__consignee_name;
                        if (pobj.data.result[i].shipmentTypeDesc == '自提') {
                            $('ddxtdonetb').rows[i].cells[10].innerHTML = '自提';
                        } else {
                            $('ddxtdonetb').rows[i].cells[10].innerHTML = pobj.data.result[i].produce_order__consignee_address.replace('湖北省 武汉市 ', '').replace('湖北省武汉市', '');
                        }
                        bind_qrcode($('ddxtdonetb').rows[i].cells[8].lastChild, '多点', 10, 9, 8);
                    }
                    $('ddxtdp').style.display = '';//取消div的隐藏
                    myec &= ~192;
                    loadnum[0] = 9;
                } catch (error) {
                    myec |= 64;
                    loadnum[0] = 9;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                myec |= 128;
                console.log(err);
                loadnum[0] = 9;
            }
        });
    };//取多点已完成订单
    var rehb_wait_pack = function () {
        for (var i = 0; i < $('hbxttb').rows.length; i++) {
            var d2 = new Date($('hbxttb').rows[i].cells[4].innerText);
            var d2Ms = d2.getTime();
            $('hbxttb').rows[i].cells[3].innerHTML = reovertime(d2Ms);
            var nowhb = new Date();//获取到当前的时间
            var nowMshb = nowhb.getTime();
            var lineghb = d2Ms - nowMshb;//相差的毫秒数
            re_time_line($('hbxttb').rows[i], lineghb);
        }
    };//刷新海博拣货剩余时长
    var get_hiboos_wait_pack = function () {
        loadnum[1] = 2;
        fetch("https://zt.hiboos.com/wmsOrder/queryOrderByPage", {
            "headers": {
                "accept": "application/json, text/plain, */*",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin"
            },
            "referrer": "https://zt.hiboos.com/index.html",
            "referrerPolicy": "no-referrer-when-downgrade",
            "body": "body=%7B%22statusSet%22%3A%5B%2220%22%5D%2C%22isFailPick%22%3Anull%2C%22isReminded%22%3Anull%7D&page=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A100%7D",
            "method": "POST",
            "mode": "cors",
            "credentials": "include"
        }).then((res) => res.json()).then(pobj => {
            oldlist = ',';
            if (pobj.result.resultList != undefined) {
                pobj.result.resultList.sort(function (a, b) {
                    if (a.orderPayTime < b.orderPayTime) {
                        return -1;
                    }
                    if (a.orderPayTime > b.orderPayTime) {
                        return 1;
                    }
                    return 0;
                });
                pobj.result.resultList.sort(function (a, b) {
                    if (a.orderPlanPickTime < b.orderPlanPickTime) {
                        return -1;
                    }
                    if (a.orderPlanPickTime > b.orderPlanPickTime) {
                        return 1;
                    }
                    return 0;
                });
                var opss = ['<span style="color: #ffffff;background: #000000;">否</span>', '是', '<span style="color: #ffffff;background: #000000;">否</span>'];
                $('hbwpack').innerText = pobj.result.resultList.length;
                var ztchannel;
                changerow('hbxttb', pobj.result.resultList.length);
                for (var i = 0; i < pobj.result.resultList.length; i++) {
                    ztchannel = pobj.result.resultList[i].channel;
                    oldlist += pobj.result.resultList[i].channelOrderId + ',';
                    $('hbxttb').rows[i].cells[0].innerHTML = '<img src="' + pplatform[ztchannel] + '" alt="" title="' + dplatform[ztchannel] + '" width="24px" height="24px"/><span style="font-size:16px;">' + pobj.result.resultList[i].daySeq + '</span>';
                    $('hbxttb').rows[i].cells[1].innerHTML = opss[pobj.result.resultList[i].orderPickerStatus];
                    $('hbxttb').rows[i].cells[2].innerHTML = '<a href="https://zt.hiboos.com/index.html#/ordercenter/orderdetail/' + pobj.result.resultList[i].orderId + '" target="_blank" title="点击进入订单详情">' + pobj.result.resultList[i].skuKindTotal + '种' + pobj.result.resultList[i].skuNumTotal + '件</a>';
                    $('hbxttb').rows[i].cells[4].innerHTML = pobj.result.resultList[i].orderPlanPickTime;
                    $('hbxttb').rows[i].cells[5].innerHTML = '<a href title="显示二维码">' + pobj.result.resultList[i].recipientPhone + '</a>';
                    $('hbxttb').rows[i].cells[6].innerHTML = pobj.result.resultList[i].recipientAddress;
                    bind_qrcode($('hbxttb').rows[i].cells[5].lastChild, dplatform[ztchannel], 6, '隐私号', 5);
                }
                rehb_wait_pack();
            } else {
                $('hbwpack').innerText = 0;
                changerow('hbxttb', 0);
            }
            $('hbxtdp').style.display = '';
            myec &= ~65536;
            loadnum[1] = 3;
        }).catch(err => {
            myec |= 65536;
            console.log(err);
            loadnum[1] = 3;
        });
    };//取海博未拣货订单
    var rehb_wait_done = function () {
        for (var i = 0; i < $('hbxtptb').rows.length; i++) {
            var d2 = new Date($('hbxtptb').rows[i].cells[3].innerHTML);
            var d2Ms = d2.getTime();
            $('hbxtptb').rows[i].cells[2].innerHTML = reovertime(d2Ms);
            var nowhbp = new Date();//获取到当前的时间
            var nowMshbp = nowhbp.getTime();
            var lineghbp = d2Ms - nowMshbp;//相差的毫秒数
            re_time_line($('hbxtptb').rows[i], lineghbp);
        }
    };//更新海博配送剩余时长
    var get_hiboos_wait_done = function () {
        loadnum[1] = 4;
        fetch("https://zt.hiboos.com/wmsOrder/queryOrderByPage", {
            "headers": {
                "accept": "application/json, text/plain, */*",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/x-www-form-urlencoded",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin"
            },
            "referrer": "https://zt.hiboos.com/index.html",
            "referrerPolicy": "no-referrer-when-downgrade",
            "body": "body=%7B%22statusSet%22%3A%5B%2230%22%5D%2C%22isFailPick%22%3Anull%2C%22isReminded%22%3Anull%7D&page=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A100%7D",
            "method": "POST",
            "mode": "cors",
            "credentials": "include"
        }).then((res) => res.json()).then(pobj => {
            if (pobj.result.resultList != undefined) {
                pobj.result.resultList.sort(function (a, b) {
                    if (a.orderPayTime < b.orderPayTime) {
                        return -1;
                    }
                    if (a.orderPayTime > b.orderPayTime) {
                        return 1;
                    }
                    return 0;
                });
                pobj.result.resultList.sort(function (a, b) {
                    if (a.logisticsPreEnd < b.logisticsPreEnd) {
                        return -1;
                    }
                    if (a.logisticsPreEnd > b.logisticsPreEnd) {
                        return 1;
                    }
                    return 0;
                });
                $('hbwdone').innerText = pobj.result.resultList.length;
                changerow('hbxtptb', pobj.result.resultList.length);
                var ztchannel;
                for (var i = 0; i < pobj.result.resultList.length; i++) {
                    ztchannel = pobj.result.resultList[i].channel;
                    oldlist += pobj.result.resultList[i].channelOrderId + ',';
                    $('hbxtptb').rows[i].cells[0].innerHTML = '<img src="' + pplatform[ztchannel] + '" alt="" title="' + dplatform[ztchannel] + '" width="24px" height="24px"/><span style="font-size:16px;">' + pobj.result.resultList[i].daySeq + '</span>';
                    $('hbxtptb').rows[i].cells[1].innerHTML = '<a href="https://zt.hiboos.com/index.html#/ordercenter/orderdetail/' + pobj.result.resultList[i].orderId + '" target="_blank" title="点击进入订单详情">' + pobj.result.resultList[i].skuKindTotal + '种' + pobj.result.resultList[i].skuNumTotal + '件</a>';
                    $('hbxtptb').rows[i].cells[3].innerHTML = pobj.result.resultList[i].logisticsPreEnd;
                    $('hbxtptb').rows[i].cells[4].innerHTML = '<a href title="显示二维码">' + pobj.result.resultList[i].recipientPhone + '</a>';
                    $('hbxtptb').rows[i].cells[5].innerHTML = pobj.result.resultList[i].recipientAddress;
                    bind_qrcode($('hbxtptb').rows[i].cells[4].lastChild, dplatform[ztchannel], 5, '隐私号', 4);
                }
                rehb_wait_done();
            } else {
                $('hbwdone').innerText = 0;
                changerow('hbxtptb', 0);
            }
            $('hbxtdp').style.display = '';
            myec &= ~131072;
            loadnum[1] = 5;
        }).catch(err => {
            myec |= 131072;
            console.log(err);
            loadnum[1] = 5;
        });
    };//取海博未完成订单
    var get_jddj_wait_pack = function () {
        loadnum[1] = 6;
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://order.jddj.com/order/newManager/tabQuery/waitPrint?o2oOrderType=10000&pageNo=1&pageSize=100&desc=true",
            "headers": {
                "accept": "application/json, text/javascript, */*; q=0.01",
                "accept-language": "zh-CN,zh;q=0.9",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin",
                "x-requested-with": "XMLHttpRequest",
                "referrer": "https://order.jddj.com/static/web/html/pick_assistant.html",
                "referrerPolicy": "strict-origin-when-cross-origin",
                "mode": "cors",
                "credentials": "include"
            },
            onload: function (res) {
                try {
                    var pobj = (JSON.parse(res.responseText));
                    //oldlist = ',';
                    var hdefect = 0;
                    for (var i = 0; i < pobj.result.newOrderinfoMains.resultList.length; i++) {
                        if (oldlist.indexOf(',' + pobj.result.newOrderinfoMains.resultList[i].deliverNo + ',') == -1) {
                            changerow('jddftb', hdefect + 1);
                            $('jddftb').rows[hdefect].cells[0].innerHTML = pobj.result.newOrderinfoMains.resultList[i].orderNo;
                            $('jddftb').rows[hdefect].cells[1].innerHTML = pobj.result.newOrderinfoMains.resultList[i].deliverNo;
                            $('jddftb').rows[hdefect].cells[2].innerHTML = '<a href="https://order.jddj.com/order/export/orderDetail_es?orderId=' + pobj.result.newOrderinfoMains.resultList[i].deliverNo + '&orderSource=1" target="_blank" title="点击进入订单详情">' + pobj.result.newOrderinfoMains.resultList[i].listOrderinfoproduct.length + '种' + pobj.result.newOrderinfoMains.resultList[i].sumProduct + '件</a>';
                            $('jddftb').rows[hdefect].cells[3].innerHTML = pobj.result.newOrderinfoMains.resultList[i].orderPreStartDeliveryTime;
                            $('jddftb').rows[hdefect].cells[4].innerHTML = pobj.result.newOrderinfoMains.resultList[i].orderPaidTime;
                            $('jddftb').rows[hdefect].cells[5].innerHTML = pobj.result.newOrderinfoMains.resultList[i].fullname;
                            $('jddftb').rows[hdefect].cells[6].innerHTML = '<a href title="显示二维码">' + pobj.result.newOrderinfoMains.resultList[i].mobile + '</a>';
                            $('jddftb').rows[hdefect].cells[7].innerHTML = pobj.result.newOrderinfoMains.resultList[i].fullAddress;
                            bind_qrcode($('jddftb').rows[hdefect].cells[6].lastChild, '京东', 7, 5, 6);
                            hdefect += 1;
                        }
                    }
                    if (hdefect > 0) {
                        $('jdamount').innerText = hdefect;
                        $('jddf').style.display = '';
                    } else {
                        $('jddf').style.display = 'none';
                    }
                    loadnum[1] = 7;
                } catch (error) {
                    loadnum[1] = 7;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (err) {
                console.log(err);
                loadnum[1] = 7;
            }
        });
    };//取京东未拣货订单
    var get_mtwm_wait_pack = function () {
        loadnum[1] = 8;
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://shangoue.meituan.com/v2/order/pre/r/query?getNewVo=1&queryType=1&wmOrderStatus=4&wmOrderLogisticsStatus=-2&sortField=1&startDate=" + getstrtime() + "&endDate=" + getstrtime() + "&pageNum=1",
            "headers": {
                "accept": "*/*",
                "accept-language": "zh-CN,zh;q=0.9",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin",
                "x-requested-with": "XMLHttpRequest"
            },
            onload: function (res) {
                try {
                    var pobj = (JSON.parse(res.responseText));
                    var hdefect = 0;
                    for (var i = 0; i < pobj.wmOrderList.length; i++) {
                        if (oldlist.indexOf(',' + pobj.wmOrderList[i].wm_order_id_view_str + ',') == -1) {
                            changerow('mtdftb', hdefect + 1);
                            $('mtdftb').rows[hdefect].cells[0].innerHTML = pobj.wmOrderList[i].num;
                            $('mtdftb').rows[hdefect].cells[1].innerHTML = pobj.wmOrderList[i].wm_order_id_view_str;
                            $('mtdftb').rows[hdefect].cells[2].innerHTML = pobj.wmOrderList[i].total_items + '件';
                            var cdate = new Date(pobj.wmOrderList[i].delivery_btime_fmt);
                            cdate.setMinutes(cdate.getMinutes() - 30);
                            $('mtdftb').rows[hdefect].cells[3].innerHTML = cdate.getFullYear() + '-' + (cdate.getMonth() + 1) + '-' + cdate.getDate() + ' ' + cdate.getHours() + ':' + cdate.getMinutes() + ':' + cdate.getSeconds();
                            $('mtdftb').rows[hdefect].cells[4].innerHTML = pobj.wmOrderList[i].order_time_fmt;
                            $('mtdftb').rows[hdefect].cells[5].innerHTML = pobj.wmOrderList[i].recipient_name;
                            $('mtdftb').rows[hdefect].cells[6].innerHTML = '<a href title="显示二维码">' + pobj.wmOrderList[i].privacy_phone + '</a>';
                            $('mtdftb').rows[hdefect].cells[7].innerHTML = pobj.wmOrderList[i].recipient_address;
                            bind_qrcode($('mtdftb').rows[hdefect].cells[6].lastChild, '美团', 7, 5, 6);
                            hdefect += 1;
                        }
                    }
                    if (hdefect > 0) {
                        $('mtamount').innerText = hdefect;
                        $('mtdf').style.display = '';
                    } else {
                        $('mtdf').style.display = 'none';
                    }
                    loadnum[1] = 9;
                } catch (error) {
                    loadnum[1] = 9;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (a) {
                console.log(a);
                loadnum[1] = 9;
            }
        });
    };//取美团未拣货订单
    var get_elem_wait_pack = function () {
        loadnum[1] = 10;
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://be.ele.me/crm/getpicklist?page=1",
            "headers": {
                "accept": "application/json",
                "accept-language": "zh-CN,zh;q=0.9",
                "content-type": "application/json",
                "sec-ch-ua": "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\"",
                "sec-ch-ua-mobile": "?0",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site",
                "x-shard": "nrshopid=32267333714",
                "referrer": "https://nr.ele.me/",
                "referrerPolicy": "strict-origin-when-cross-origin",
                "mode": "cors",
                "credentials": "include"
            },
            onload: function (res) {
                try {
                    var pobj = (JSON.parse(res.responseText));
                    var hdefect = 0;
                    //oldlist = ',';
                    for (var i = 0; i < pobj.data.order_list.length; i++) {
                        if (oldlist.indexOf(',' + pobj.data.order_list[i].order_basic.eleme_order_id + ',') == -1) {
                            changerow('eldftb', hdefect + 1);
                            $('eldftb').rows[hdefect].cells[0].innerHTML = pobj.data.order_list[i].order_basic.order_index;
                            $('eldftb').rows[hdefect].cells[1].innerHTML = pobj.data.order_list[i].order_basic.eleme_order_id;
                            $('eldftb').rows[hdefect].cells[2].innerHTML = pobj.data.order_list[i].order_goods.goods_list.length + '种' + pobj.data.order_list[i].order_goods.goods_total + '件';
                            $('eldftb').rows[hdefect].cells[3].innerHTML = pobj.data.order_list[i].order_basic.pick_info.expect_finish_time;
                            $('eldftb').rows[hdefect].cells[4].innerHTML = '未获取';
                            $('eldftb').rows[hdefect].cells[5].innerHTML = pobj.data.order_list[i].order_basic.user_real_name;
                            $('eldftb').rows[hdefect].cells[6].innerHTML = '<a href title="显示二维码">' + pobj.data.order_list[i].order_basic.user_phone.replace('转', ',') + '</a>';
                            $('eldftb').rows[hdefect].cells[7].innerHTML = pobj.data.order_list[i].order_basic.user_address;
                            bind_qrcode($('eldftb').rows[hdefect].cells[6].lastChild, '饿了么', 7, 5, 6);
                            hdefect += 1;
                        }
                    }
                    if (hdefect > 0) {
                        $('elamount').innerText = hdefect;
                        $('eldf').style.display = '';
                    } else {
                        $('eldf').style.display = 'none';
                    }
                    loadnum[1] = 11;
                } catch (error) {
                    loadnum[1] = 11;
                    console.log('*');
                    console.log(error.message);
                    console.log('*');
                }
            },
            onerror: function (a) {
                console.log(a);
                loadnum[1] = 11;
            }
        });
    };//取饿了么未拣货订单
    var get_myec = function () {
        var subec = myec + 20201029;
        subec = subec.toString(16);
        if (subec.length < 8) {
            subec = '0x' + ('0'.repeat(8 - subec.length) + subec).toUpperCase();
        }
        return subec;
    };//生成错误码
    var show_ec = function () {
        if (myec & 65535) {
            $('dmecd').innerText = get_myec();
            $('ddxtnli').style.display = '';
        } else {
            $('ddxtnli').style.display = 'none';
        }
        if (myec & 4294901760) {
            $('hbxtnli').style.display = '';
            $('hbecd').innerText = get_myec();
        } else {
            $('hbxtnli').style.display = 'none';
        }
    };//显示错误码
    var loadallpage = function () {
        switch (loadnum[0]) {
            case 1:
                if ($('storeid').selectedOptions[0] == undefined) {
                    get_dmall_id();
                } else {
                    loadnum[0] = 3;
                };
                break;
            case 3:
                get_dmall_wait_pack();
                break;
            case 5:
                get_dmall_wait_done();
                break;
            case 7:
                get_dmall_done();
                break;
        }
        switch (loadnum[1]) {
            case 1:
                get_hiboos_wait_pack();
                break;
            case 3:
                get_hiboos_wait_done();
                break;
            case 5:
                get_jddj_wait_pack();
                break;
            case 7:
                get_mtwm_wait_pack();
                break;
            case 9:
                get_elem_wait_pack();
                break;
        }
        // if (loadnum[0] == 1) {
        //     if ($('storeid').selectedOptions[0] == undefined) {
        //         get_dmall_id();
        //     } else {
        //         loadnum[0] = 3;
        //     };
        //     get_dmall_wait_pack();
        //     get_dmall_wait_done();
        //     get_dmall_done();
        // }
        // if (loadnum[1] == 1) {
        //     get_hiboos_wait_pack();
        //     get_hiboos_wait_done();
        //     get_jddj_wait_pack();
        //     get_mtwm_wait_pack();
        //     get_elem_wait_pack();
        // }
    };//控制读取哪个页面
    var qrm = new QRCode($('p_qrcode'), { width: 256, height: 256 });//初始化二维码要用的div
    var mretime = 0;
    var autoref = (function () {
        loadallpage();
        mretime += 1;
        mretime %= 66;
        if (mretime == 0) {
            if (loadnum[0] & 1) {
                loadnum[0] = 1;
            }
            if (loadnum[1] & 1) {
                loadnum[1] = 1;
            }
        }
        redm_wait_pack();
        redm_wait_done();
        rehb_wait_pack();
        rehb_wait_done();
        show_ec();
        setTimeout(autoref, 1000);
    });//计时器系统
    autoref();
    // Your code here...
})();